<?php defined('SYSPATH') or die('No direct script access.');

 class Controller_Review extends Controller{
    //post评论
    public function action_add(){

      $user=Session::instance()->get('user');

      if(empty($user)){

        $result['code']='0x00001';

        exit(json_encode($result));

      }

      $postid=$this->request->post('id');

      if(empty($postid)){

        $result['code']='0x0000x';

        exit(json_encode($result));

      }

      $content=$this->request->post('content');

      if(empty($content)){

        $result['code']='0x0000x';

        $result['info']='请输入内容';

        exit(json_encode($result));

      }

      $images=$this->request->post('images');

      $result=array();

      if(!empty($user)){

        $userid=$user["userid"];

        $model=new Model_Review();

        $result=$model->add($userid,$postid,$content,$images);

      }
      else{

        $result['code']='0x00001';

      }

      exit(json_encode($result));

    }

    //post评论
    public function action_getInfo(){

      $postid=$this->request->post('postid');

      $offset=$this->request->post('offset');

      if(empty($postid)){

        $result['code']='0x0000x';

        exit(json_encode($result));

      }

      $result=array();

      $model_review=new Model_Review();

      $result=$model_review->getInfo($postid,$offset,10);

      exit(json_encode($result));

    }

    //post评论回复
    public function action_getReplyInfo(){

      $postid=$this->request->post('postid');

      $review_id=$this->request->post('review_id');

      if(empty($postid)||empty($review_id)){

        $result['code']='0x0000x';

        exit(json_encode($result));

      }

      $result=array();

      $model=new Model_Review();

      $result=$model->getReplyInfo($postid,$review_id);

      exit(json_encode($result));

    }

     //post评论回复
    public function action_reply(){

      $user=Session::instance()->get('user');

      if(empty($user)){

        $result['code']='0x00001';

        exit(json_encode($result));

      }

      $postid=$this->request->post('id');

      if(empty($postid)){

        $result['code']='0x0000x';

        exit(json_encode($result));

      }

      $content=$this->request->post('content');

      $review_id=$this->request->post('review_id');

      $parent_id=$this->request->post('parent_id');

      if(empty($content)){

        $result['code']='0x0000x';

        $result['info']='请输入内容';

        exit(json_encode($result));

      }

      $result=array();

      if(!empty($user)){

        $userid=$user["userid"];

        $model=new Model_Review();

        $result=$model->reply($userid,$postid,$review_id,$parent_id,$content);

      }
      else{

        $result['code']='0x00001';

      }

      exit(json_encode($result));

    }

 } 
